package com.his.controller;

import com.his.entity.ResponseResult;
import com.his.entity.User;
import com.his.service.LoginService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "LoginController--登录")
@RestController
public class LoginController {

    @Autowired
    private LoginService loginService;

    @Operation(summary = "退出登录",description = "输入：无。 返回：token")
    @PostMapping("/user/logout")
    public ResponseResult logout(){
        return loginService.logout();
    }

    @Operation(summary = "登录",description = "输入：User（用户名，密码）。 返回：token")
    @PostMapping("/user/login")
    public ResponseResult login(@RequestBody User user){
        return loginService.login(user);
    }


    @Operation(summary = "登录人信息",description = "输入：User（空数据的就行，记得传一个空的大括号，不然会报错 {} ）。 返回：一个User信息")
    @PostMapping("/user/query")
    public ResponseResult query(@RequestBody User user){
        return loginService.query(user);
    }

    @Operation(summary = "测试",description = "测试用的不用管")
    @PostMapping("/user/say")
    @PreAuthorize("hasAuthority('administrator')")
    public String hello() {
        return "Hello Security";
    }


}
